package com.qzsf.backend.mapper;

import com.qzsf.backend.entity.Feedback;
import com.qzsf.backend.mapper.sql.FeedbackSqlProvider;
import com.qzsf.backend.vo.FeedbackVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/24 21:57 周日
 * @Email 1429278462@qq.com
 * @Remark 反馈数据访问层
 * @Version 1.0
 */
@Mapper
@Repository
public interface FeedbackMapper {
    @SelectProvider(type = FeedbackSqlProvider.class,method = "getFeedbackByCondition")
    List<FeedbackVO> getFeedbackByCondition(Integer typeId,Integer eventId);

    int countFeedbacks(Integer eventId,Integer typeId);

    List<Map<String,Object>> getRatingDistribution(Integer eventId,Integer typeId);

    Double getAverageRating(Integer eventId,Integer typeId);

    int countUniqueParticipants(Integer eventId,Integer typeId);

    @Select("select * from feedback where user_id = #{id} and event_id = #{eventId}")
    Feedback getFeedbackByUserAndEvent(int id,int eventId);

    @Insert("insert into feedback (user_id, event_id, rating, content) values (#{userId},#{eventId},#{rating},#{content})")
    int createFeedback(Feedback feedback);
}
